// components/article/article.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    content: {
      type: Object,
      value: {}
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    textClass: {
      type: String,
      value: ''
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    previewImage: function () {
      wx.previewImage({
        urls: [this.data.content.value.url],
      });
    }
  },

  lifetimes: {
    attached: function () {
      if (this.data.content.type === 'text') {
        let textClass = 'text';
        if (this.data.content.value.hasOwnProperty('format')) {
          const format = this.data.content.value.format;
          if (format.bold) {
            textClass += ' bold'; // notice the space leading the string
          }
          if (format.underline) {
            textClass += ' underline';
          }
          if (format.italic) {
            textClass += ' italic';
          }
        }
        this.setData({
          textClass: textClass
        });
      }
    }
  }
})
